﻿using System.Linq;
using System.Collections.Specialized;
using System.Web;
using System.Globalization;

namespace LogOnWithACSLibrary
{
    public static class NameValueCollectionExtensions
    {
        /// <summary>
        /// Greates query string using the name value collection
        /// </summary>
        /// <param name="collection"></param>
        /// <returns></returns>
        public static string ToQueryString(this NameValueCollection collection)
        {
            return string.Join("&",
                from k in collection.AllKeys
                select string.Format(CultureInfo.InvariantCulture,
                    "{0}={1}",
                    k,
                    HttpUtility.UrlEncode(collection.GetValues(k)[0])));
        }
    }
}
